﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KD.Sms.DAL.Sqlserver
{
    internal sealed partial class Interface
    {
        /// <summary>
        /// 本类的唯一实例
        /// </summary>
        private static Interface OWNER = null;

        /// <summary>
        /// 私有构造函数
        /// </summary>
        private Interface()
        {
        }

        /// <summary>
        /// 获取类的唯一实例
        /// </summary>
        /// <returns></returns>
        public static Interface Instance
        {
            get
            {
                if (Interface.OWNER == null)
                {
                    Interface.OWNER = new Interface();
                }
                return Interface.OWNER;
            }
        }


        /// <summary>
        /// 根据卡号提取物流信息
        /// </summary>
        /// <param name="cardno"></param>
        /// <returns></returns>
        public System.Data.DataTable DoQueryCarNumByCarNumOrCard(string CarNumOrCard, bool isCard)
        {
            //var _strSql = string.Format(@"select t.cardno,t.truckno as carno,t.product as kind,t.Specification as material,t.sender as supplier,t.transporter as transport
            //                                ,0 as totallength,0 as totalwidth,0 as clength,0 as cwidth,0 as cheight,'' as cpostion
            //                                ,Sparestr8 
            //                                from cardinfo t 
            //                                where t.{1} = '{0}'
            //                                and truckno is not null and truckno <>''
            //                                and Specification in (select distinct a.specification from [SpecifList] a where SpareStr1 = '1')", CarNumOrCard, isCard ? "cardno" : "truckno");
            //sparestr1
            var _strSql = string.Format("select * from V_CardInfoForSampling where {1} = '{0}'", CarNumOrCard, isCard ? "cardno" : "carno");
            return SqlHelper.GetDataTable(_strSql);
        }

        /// <summary>
        /// 更新当前车辆采样完成
        /// </summary>
        /// <param name="cardno"></param>
        /// <returns></returns>
        public bool DoUpdateSamplingEndToWl(string cardno)
        {
            var _strSql = string.Format("update CardInfo  set Sparestr8 = '2' where Cardno = '{0}'", cardno);
            return SqlHelper.ExecuteNonQuery(_strSql, null) > 0;
        }

    }
}
